package com.study.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
 * 跳转页面
 * 所有jsp页面 都要通过 pageServlet 进行跳转
 * 所有的jsp都放在/WEB-INF/page文件夹下
 *
 *
 */
@WebServlet("/page/*")
public class PageController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String url = req.getRequestURI();
        System.out.println("url: " + url);
        String servletPath = req.getServletPath();
        System.out.println("servletPath: " + servletPath);
        //  /page/*   访问page文建的路径
        String page = url.substring(url.lastIndexOf("/")); //索引
        req.getRequestDispatcher("../WEB-INF/page/" + page + ".jsp").forward(req, resp);
    }
}